﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Notepad_X.Components
{
    /// <summary>
    /// Static functions of the Application
    /// </summary>
    public static class Static
    {

        public static void UpdateFormControls(System.Windows.Forms.Form Form,Boolean UpdateIcons)
        {
            foreach (System.Windows.Forms.Control Control in Form.Controls) {
                if (Control.GetType() == typeof(System.Windows.Forms.MenuStrip)) {
                    UpdateMenuStrip((System.Windows.Forms.MenuStrip)Control, UpdateIcons);
                } else if (Control.GetType() == typeof(System.Windows.Forms.ToolStrip)) {
                    UpdateToolStrip((System.Windows.Forms.ToolStrip)Control, UpdateIcons);
                } else if (Control.GetType() == typeof(System.Windows.Forms.Panel)) {
                    UpdatePanel((System.Windows.Forms.Panel)Control, UpdateIcons);

                } else if (Control.GetType() == typeof(ButtonX)) {
                    UpdateButtonX((ButtonX)Control, UpdateIcons);

                } else if (Control.GetType() == typeof(LabelX)) {
                    UpdateLabelX((LabelX)Control, UpdateIcons);

                }
            }
        }

        public static void UpdatePanel(System.Windows.Forms.Panel Panel, Boolean UpdateIcons)
        {
            foreach (System.Windows.Forms.Control Item in Panel.Controls)
            {
                if (Item.GetType() == typeof(ButtonX))
                {
                    UpdateButtonX((ButtonX)Item, UpdateIcons);
                }
                else if (Item.GetType() == typeof(MenuButton))
                {
                    UpdateMenuButton((MenuButton)Item, UpdateIcons);
                }
            }
        }
        public static void UpdateUserControl(System.Windows.Forms.UserControl UserControl, Boolean UpdateIcons)
        {
            foreach (System.Windows.Forms.Control Item in UserControl.Controls)
            {
                if (Item.GetType() == typeof(ButtonX))
                {
                    UpdateButtonX((ButtonX)Item, UpdateIcons);
                }
                else if (Item.GetType() == typeof(GroupBoxX))
                {
                    UpdateGroupBoxX((GroupBoxX)Item, UpdateIcons);
                }else if (Item.GetType() == typeof(LabelX)){
                    UpdateLabelX((LabelX)Item, UpdateIcons);
                }
            }
        }
        public static void UpdateGroupBoxX(Notepad_X.Components.GroupBoxX GroupBox, Boolean UpdateIcons)
        {
            if (GroupBox.String != Notepad_X.Classes.Strings.none)
            {
                GroupBox.Text = Notepad_X.Main.app_language[GroupBox.String];
            }
            if (UpdateIcons && GroupBox.Icon != Notepad_X.Classes.Icons.none)
            {
                String IconKey = Enum.GetName(typeof(Notepad_X.Classes.Icons), GroupBox.Icon);
                if (Notepad_X.Static.MainInstance.IconsCollection.Images.ContainsKey(IconKey))
                {
                    GroupBox.BackgroundImage = Notepad_X.Static.MainInstance.IconsCollection.Images[IconKey];
                }
            }

            foreach (System.Windows.Forms.Control Item in GroupBox.Controls)
            {
                if (Item.GetType() == typeof(ButtonX))
                {
                    UpdateButtonX((ButtonX)Item, UpdateIcons);
                }
                else if (Item.GetType() == typeof(GroupBoxX))
                {
                    UpdateGroupBoxX((GroupBoxX)Item,UpdateIcons);
                }
                else if (Item.GetType() == typeof(LabelX))
                {
                    UpdateLabelX((LabelX)Item, UpdateIcons);
                }

            }
        }
        public static void UpdateMenuStrip(System.Windows.Forms.MenuStrip MenuStrip, Boolean UpdateIcons)
        {
            foreach (System.Windows.Forms.ToolStripItem Item in MenuStrip.Items)
            {
                if (Item.GetType() == typeof(MenuItemX))
                {
                    UpdateMenuItemX((MenuItemX)Item,UpdateIcons);
                }else if (Item.GetType() == typeof(ToolBarButtonX))
                {
                    UpdateToolBarButtonX((ToolBarButtonX)Item, UpdateIcons);
                }
            }
        }
        public static void UpdateToolStrip(System.Windows.Forms.ToolStrip ToolStrip, Boolean UpdateIcons)
        {
            foreach (System.Windows.Forms.ToolStripItem Item in ToolStrip.Items)
            {
                if (Item.GetType() == typeof(MenuItemX))
                {
                    UpdateMenuItemX((MenuItemX)Item, UpdateIcons);

                }else if (Item.GetType() == typeof(ToolBarButtonX))
                {
                    UpdateToolBarButtonX((ToolBarButtonX)Item, UpdateIcons);
                }
                else if (Item.GetType() == typeof(ToolBarLabelX))
                {
                    UpdateToolBarLabelX((ToolBarLabelX)Item, UpdateIcons);
                }
            }
        }

        public static void UpdateContextMenuStrip(System.Windows.Forms.ContextMenuStrip ContextMenuStrip, Boolean UpdateIcons)
        {
            foreach (System.Windows.Forms.ToolStripItem Item in ContextMenuStrip.Items)
            {
                if (Item.GetType() == typeof(MenuItemX))
                {
                    UpdateMenuItemX((MenuItemX)Item, UpdateIcons);
                }
            }
        }

        public static void UpdateLabelX(LabelX Label, Boolean UpdateIcons)
        {
            if (Label.String != Notepad_X.Classes.Strings.none)
            {
                Label.Text = Notepad_X.Main.app_language[Label.String];
            }
            if (UpdateIcons && Label.Icon != Notepad_X.Classes.Icons.none)
            {
                String IconKey = Enum.GetName(typeof(Notepad_X.Classes.Icons), Label.Icon);
                if (Notepad_X.Static.MainInstance.IconsCollection.Images.ContainsKey(IconKey))
                {
                    Label.Image = Notepad_X.Static.MainInstance.IconsCollection.Images[IconKey];
                }
            }
        }

        public static void UpdateMenuItemX(MenuItemX MenuItem, Boolean UpdateIcons)
        {
            if (MenuItem.String != Notepad_X.Classes.Strings.none)
            {
                MenuItem.Text = Notepad_X.Main.app_language[MenuItem.String];
            }
            if (UpdateIcons && MenuItem.Icon != Notepad_X.Classes.Icons.none)
            {
                String IconKey = Enum.GetName(typeof(Notepad_X.Classes.Icons), MenuItem.Icon);
                if (Notepad_X.Static.MainInstance.IconsCollection.Images.ContainsKey(IconKey))
                {
                    MenuItem.Image = Notepad_X.Static.MainInstance.IconsCollection.Images[IconKey];
                }
            }
            foreach (System.Windows.Forms.ToolStripItem Item in MenuItem.DropDownItems)
            {
                if (Item.GetType() == typeof(MenuItemX))
                {
                    UpdateMenuItemX((MenuItemX)Item, UpdateIcons);
                }
            }
        }
        public static void UpdateToolBarButtonX(ToolBarButtonX ToolBarButton, Boolean UpdateIcons)
        {
            if (ToolBarButton.String != Notepad_X.Classes.Strings.none)
            {
                ToolBarButton.Text = ToolBarButton.ToolTipText = Notepad_X.Main.app_language[ToolBarButton.String];
            }
            if (UpdateIcons && ToolBarButton.Icon != Notepad_X.Classes.Icons.none)
            {
                String IconKey = Enum.GetName(typeof(Notepad_X.Classes.Icons), ToolBarButton.Icon);
                if (Notepad_X.Static.MainInstance.IconsCollection.Images.ContainsKey(IconKey))
                {
                    ToolBarButton.Image = Notepad_X.Static.MainInstance.IconsCollection.Images[IconKey];
                }
            }
        }
        public static void UpdateToolBarLabelX(ToolBarLabelX ToolBarLabel, Boolean UpdateIcons)
        {
            if (ToolBarLabel.String != Notepad_X.Classes.Strings.none)
            {
                ToolBarLabel.Text = ToolBarLabel.ToolTipText = Notepad_X.Main.app_language[ToolBarLabel.String];
            }
            if (UpdateIcons && ToolBarLabel.Icon != Notepad_X.Classes.Icons.none)
            {
                String IconKey = Enum.GetName(typeof(Notepad_X.Classes.Icons), ToolBarLabel.Icon);
                if (Notepad_X.Static.MainInstance.IconsCollection.Images.ContainsKey(IconKey))
                {
                    ToolBarLabel.Image = Notepad_X.Static.MainInstance.IconsCollection.Images[IconKey];
                }
            }
        }
        public static void UpdateButtonX(ButtonX Button, Boolean UpdateIcons)
        {
            if (Button.String != Notepad_X.Classes.Strings.none)
            {
                Button.Text = Notepad_X.Main.app_language[Button.String];
            }
            if (UpdateIcons && Button.Icon != Notepad_X.Classes.Icons.none)
            {
                String IconKey = Enum.GetName(typeof(Notepad_X.Classes.Icons), Button.Icon);
                if (Notepad_X.Static.MainInstance.IconsCollection.Images.ContainsKey(IconKey))
                {
                    Button.Image = Notepad_X.Static.MainInstance.IconsCollection.Images[IconKey];
                }
            }
        }
        public static void UpdateMenuButton(MenuButton mButton, Boolean UpdateIcons)
        {
            if (mButton.String != Notepad_X.Classes.Strings.none)
            {
                mButton.Text = Notepad_X.Main.app_language[mButton.String];
            }
            if (UpdateIcons && mButton.Icon != Notepad_X.Classes.Icons.none)
            {
                String IconKey = Enum.GetName(typeof(Notepad_X.Classes.Icons), mButton.Icon);
                if (Notepad_X.Static.MainInstance.IconsCollection.Images.ContainsKey(IconKey))
                {
                    mButton.Image = Notepad_X.Static.MainInstance.IconsCollection.Images[IconKey];
                }
            }
        }
    }
}
